/*
 * @Description: 收藏、取消收藏
 */
import globalMethods from '@/plugins/methods';
import {fireEvent, getCollEventParams} from "@/handles/common/sdk";
import globalData from "@/plugins/data";
import {useBaseInfoWithOut} from "@/store/modules/base-info";
const useBaseInfo = useBaseInfoWithOut();

/**
 * @description:
 * @param {Object} item 当前待操作对象
 * @param {String|Number} bodyType
 * @param {String} affairId
 * @param {Number} num 收藏类型，3 正文收藏 4 附件收藏
 * @param {Boolean} boolean 不知道什么，看老逻辑传
 * @return {*}
 */
export default async function favorite(item, bodyType, affairId, num, boolean = false) {
  // eslint-disable-next-line no-case-declarations
  if (!item.hasFavorite) {
    let hook = await fireEvent('favorite', {
      ...getCollEventParams(useBaseInfo.businessData, globalData),
      type: num
    });
    if (!hook) {
      return;
    }
  }
  //收藏成功回调
  window.favoriteTip=()=>{item.hasFavorite = true}
  window[item.hasFavorite ? 'cancelFavorite' : 'favorite'](
    item.hasFavorite
      ? () => {
          //取消收藏回调
          globalMethods.message.success($.i18n('doc.cancel.collect.success.js'));
          item.hasFavorite = false;
        }
      : bodyType === '20'
      ? 2
      : 1,
    affairId,
    boolean,
    num
  );
}
